package com.gxd.quartz.task;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gxd.business.domain.Customer;
import com.gxd.business.enums.AssignStatusEnum;
import com.gxd.business.service.AllocationCustomerLogService;
import com.gxd.business.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 客户定时任务
 * @author gxd
 * @since 2025/6/16
 */
@Slf4j
@Component("customerTask")
public class CustomerTask {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private AllocationCustomerLogService allocationCustomerLogService;

    /**
     * 分配的客户数据，三天没有添加联系方式，就把状态改为未分配，数据从我的客户移到公共资源中
     */
    public void updateCustomerStatus() {
        log.info("==========我的客户三天没有添加联系方式，业务执行==========");
        // 查询分批客户并且三天没有添加联系方式的资源客户Id集合
        List<String> idList = customerService.selectDiff3DaysIdList();
        if (ObjUtil.isNotEmpty(idList)) {
            // 资源客户Id集合不为空，更新分配状态为未分配
            customerService.update(
                    Wrappers.lambdaUpdate(Customer.class)
                            .set(Customer::getAssignStatus, AssignStatusEnum.UNASSIGN.getCode()).in(Customer::getId, idList)
            );
        }
    }
}
